<?php 
namespace core\lib;
class route{
	public $ctrl;
	public $action;
	public function __construct(){
		p('route_start');
		if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'){
			$path = $_SERVER['REQUEST_URI'];
			$patharr = explode('/', trim($path,'/'));
			// p($patharr);
			if(isset($patharr[0])){
				$this->ctrl = $patharr[0];
				unset($patharr[0]);
			}
			if(isset($patharr[1])){
				$this->action = $patharr[1];
				unset($patharr[1]);
			}else{
				// $this->action = 'index';
				$this->action = conf::get('ACTION','route');
			}
			//url 多余部分转换为get参数
			$count = count($patharr)+2;
			// p($patharr);
			$i = 2;
			while($i < $count){
				if(isset($patharr[$i + 1])){
					$_GET[$patharr[$i]] = $patharr[$i + 1];
				}
				$i +=2;
			}
			// p($_GET);
		}else{
			$this->ctrl = conf::get('CTRL','route');
			$this->action = conf::get('ACTION','route');
		}
	}
}